/**
 * @license Modifica e usa come vuoi
 *
 * Creato da TurboLab.it - 01/01/2014 (buon anno!)
 */
CKEDITOR.dialog.add( 'codepenDialog', function( editor ) {

    return {
        title: 'Codepen',
        minWidth: 400,
        minHeight: 75,
        contents: [
            {
                id: 'tab-basic',
                label: 'Basic Settings',
                elements: [
                    {
                        type: 'text',
                        id: 'codepenUrl',
                        label: 'Codepen 連結'
                    }
                ]
            }
        ],
        onOk: function() {
            var dialog = this;
            var url = dialog.getValueOf( 'tab-basic', 'codepenUrl').trim();
            var urls = url.split("/");
            
            if(urls==null || urls[4]!='pen'){
				alert("請輸入有效的Codepen連結");
				return false;
			}
            var str = "<span data-height='400' data-theme-id='0' data-slug-hash='"+urls[5]+"' data-default-tab='result' class='codepen'>" +
            		"See the Pen <a href='"+url+"'>"+urls[5]+"</a> by "+urls[3]+" (<a href='http://codepen.io/"+urls[3]+"'>@"+urls[3]+"</a>) on " +
            		"<a href='http://codepen.io'>CodePen</a>.</span>" +
            		"<script async src='http://codepen.io/assets/embed/ei.js'></script><br>";
            editor.insertHtml(str);
        }
    };
});